<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html>
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>便民服务平台3.0</title>

</head>
<body>

<jsp:include page="../include/header.jsp"/>

<script src="<c:url value='/resource/js/lib/template.js'/>"></script>

<div class="matters-container">
    <div class="mc-hd">
        <p class="consult-t">queryCenter</p>
        <h1 class="consult-h1">专注高端”互联网+政务”设计</h1>
        <div class="type-wrap">
            <h2 class="typedH2">慧眼看世界，在政务服务的路上不断追求创新！</h2>
        </div>
    </div>
    <div class="mc-bd">
        <div class="container">
            <div class="row">
                <div class="col-sm-9">
                    <div class="consult-content">
                        <div class="consult-hd">
                            <form class="form-inline" role="form">
                                <div class="form-group">
                                    <label>问题关键词：</label>
                                    <input type="text" id="keyword" name="keyword" value="" maxlength="20"
                                           class="form-control" placeholder="请输入问题关键词">
                                </div>
                                <div class="form-group">
                                    <label>提问时间：</label>
                                    <input type="text" id="startTime" name="startTime"
                                           class="form-control laydate-icon" style="cursor:pointer;"
                                           readonly="readonly"> 至
                                    <input type="text" id="endTime" name="startTime" class="form-control laydate-icon"
                                           style="cursor: pointer;" readonly="readonly">
                                </div>
                                <div class="form-group">
                                    <button type="button" class="btn btn-blue" id="search">查询</button>
                                </div>
                            </form>
                        </div>
                        <div class="consult-bd">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <h3 class="panel-title">
                                        互联网便民服务平台便民咨询栏目只提供关于行政许可、行政审批和管理服务事项的咨询。<br>
                                        <c:if test="${current_member==null}">
                                            <span style="color:orange;">请先登录，再进行咨询。</span>
                                        </c:if>
                                    </h3>
                                    <ul id="getValue">
                                        <li><a href="javascript:;"><span name="category">出入境热点问题</span></a>
                                        </li>
                                        <li><a href="javascript:;"><span name="category">法制热点问题</span></a>
                                        </li>
                                        <li><a href="javascript:;"><span name="category">户政热点问题</span></a>
                                        </li>
                                        <li><a href="javascript:;"><span name="category">交警热点问题</span></a>
                                        </li>
                                        <li><a href="javascript:;"><span name="category">治安热点问题</span></a>
                                        </li>
                                    </ul>

                                    <button type="button" class="btn btn-green" id="ShowMyConsult">
                                        我要咨询
                                    </button>
                                </div>
                                <div class="panel-body">
                                    <div class="consults" id="mydv"></div>
                                </div>
                            </div>
                            <div style="text-align: center;">
                                <div id="page" class="pagination"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="panel panel-default panel-side">
                        <div class="panel-heading">
                            <h3 class="panel-title">新闻</h3>
                        </div>
                        <div class="panel-body">
                            <ul class="nb-list">
                                <c:forEach var="xw" items="${xwList.data.list}" varStatus="index">
                                    <li><a href="<c:url value='/news/newsdetail'/>?guid=${xw.guid}&type=''"
                                           target="_blank">${xw.title}</a></li>
                                </c:forEach>
                            </ul>
                        </div>
                    </div>
                    <div class="panel panel-default panel-side">
                        <div class="panel-heading">
                            <h3 class="panel-title">通知公告</h3>
                        </div>
                        <div class="panel-body">
                            <ul class="nb-list">
                                <c:forEach var="gsgg" items="${gsggList.data.list}" varStatus="index">
                                    <li><a href="<c:url value='/news/newsdetail'/>?guid=${gsgg.guid}&type=gsgg"
                                           target="_blank">${gsgg.title}</a></li>
                                </c:forEach>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>


<jsp:include page="../include/footer.jsp"/>

<script src="<c:url value='/resource/js/require.js'/>" data-main="<c:url value='/resource/js/main.js'/>"
        id="current-page" current-page="consultCenter"></script>

<script>
    var browserurl = window.document.location.pathname;
    var context = browserurl.indexOf("/") != -1 ? browserurl.substring(0, browserurl.substr(1).indexOf('/') + 1) : "";
    require.config({
        baseUrl: context + "/resource/js",
        paths: {
            jquery: 'jquery-1.9.1.min',
            bootstrap: "lib/bootstrap.min",
            fileupload: "jquery.fileupload",
            toastr: "toastr",
            jqPaginator: "lib/jqPaginator"
        }
    });
    require(["jquery", "jqPaginator", "fileupload", "toastr", "bootstrap"],
            function ($, jqPaginator, fileupload, toastr, bootstrap) {
                var c = "";
                $(document).ready(function () {
                    getList(1, 5);
                    $('#search').click(function () {
                        getList(1, 5);
                    });

                    $('#ShowMyConsult').click(function () {
                        var consultant='${current_member.guid}';
                        if(consultant==''){
                            $(".login-a").trigger('click');
                            return;
                        }else{
                            window.location.href="<c:url value="/handyconsult/myconsult"></c:url>";
                        }
                    });

                    $("#getValue>li>a").click(function () {
                        c = $(this).find("span").html();
                        getList(1, 5);
                        console.log(c);
                    })

                });

                function getList(pi, ps) {
                    var keyword = $("#keyword").val().trim();
                    var starttime = $("#startTime").val();
                    var endtime = $("#endTime").val();
                    var category = c;
                    $.ajax({
                        url: "<c:url value='/handyconsult/page'/>",
                        type: "GET",
                        data: {
                            kw: keyword,
                            ps: ps,
                            pi: pi,
                            st: starttime,
                            ispublic: '1',
                            sb: 'cos_time',
                            sd: 'desc',
                            et: endtime,
                            category: category,
                            status:'1'
                        },
                        dataType: "json",
                        success: function (res) {
                            if (res.succ) {
                                c = "";
                                $(".consults").html("");
                                var kw=$("#keyword").val().trim();
                                console.log(kw);
                                if(res.data.list.length<=0){
                                    $(".consults").append('<div>暂无数据</div>');
                                }

                                $.each(res.data.list, function (index, obj) {
//                                    var name = "";
//                                    if (obj.anonymous == 'Y') {
//                                        name = '匿名用户';
//                                    } else {
//                                        if (obj.telephone != null && obj.telephone != '') {
//                                            name = obj.telephone.substring(0, 7) + "****";
//                                        }
//                                    }
                                    var name = obj.telephone.substring(0, 7) + "****";

                                    var html =
                                            '<div class="media">' +
                                            '<a class="media-left" href="#">' +
                                            '<span class="media-avatar"><img src="<%=request.getContextPath()%>/resource/images/p-01.jpg"></span>' +
                                            '</a>' +
                                            '<div class="media-body">' +
                                            '<h4 class="media-heading">' +
                                            '<span class="text-green">' + Search(kw, name) + '</span> ' + Search(kw, obj.cosTime) +
                                            '</h4>' +
                                            '<div class="media-text">';
                                    var span = "";
                                    var font = "";
                                    if (obj.content.length > 44) {
                                        font = obj.content.substring(0, 44);
                                        span = obj.content.substring(44);
                                        html += '<p>' + Search(kw, font) + '</p>' +
                                                '<p class="more-mt">' + Search(kw, span) + '</p>' +
                                                '<a href="javascript:;" class="m-sh">展开</a>';
                                    } else {
                                        html += Search(kw, obj.content);
                                    }
                                    html += '</div>'
                                            + '<div class="media">'
                                            + '<a class="media-left" href="#">'
                                            + '<span class="media-avatar"><img src="<%=request.getContextPath()%>/resource/images/p-02.jpg"></span>'
                                            + '</a>'
                                            + '<div class="media-body">'
                                            + '<h4 class="media-heading">'
                                            + '<span class="text-blue">【管理员回复】</span>：';
                                    if (obj.consultAnswer != null) {
                                        html += Search(kw, obj.consultAnswer.answerTime)
                                                + '</h4>'
                                                + '<div class="media-text">';
                                        var spanContent = "";
                                        var fontContent = "";
                                        if(obj.consultAnswer.conetent!=null){
                                            if (obj.consultAnswer.conetent.length > 45) {
                                                fontContent = obj.consultAnswer.conetent.substring(0, 45);
                                                spanContent = obj.consultAnswer.conetent.substring(45);
                                                html += '<p>' + Search(kw, fontContent) + '</p>' +
                                                        '<p class="more-mt">' + Search(kw, spanContent) + '</p>' +
                                                        '<a href="javascript:;" class="m-sh">展开</a>';
                                            } else {
                                                html += Search(kw, obj.consultAnswer.conetent);
                                            }
                                        }
                                    }
                                    html += '</div>'
                                            + '</div>'
                                            + '</div>'
                                            + '</div>'
                                            + '</div>';
                                    $(".consults").append(html);
                                });
                                loadPage(res, pi, ps);
                                //显示隐藏 提问回答多余文字
                                $(".m-sh").click(function () {
                                    if ($(this).parent().find(".more-mt").is(":visible")) {
                                        $(this).parent().find(".more-mt").hide();
                                        $(this).html("展开")
                                    } else {
                                        $(this).parent().find(".more-mt").show();
                                        $(this).html("隐藏")
                                    }
                                });
                            } else {
                                toast(res.msg);
                            }
                        },
                        error: function (res) {
                            toast(res.msg);
                        }
                    });
                }

                function Search(keyword, temp) {
                    var words = unescape(keyword.replace(/\+/g, ' ')).split(/\s+/);
                    //替换关键字
                    var w;
                    for (w = 0; w < words.length; w++) {
                        var r = new RegExp("(" + words[w].replace(/[(){}.+*?^$|\\\[\]]/g, "\\$&") + ")", "ig");
//                        console.log(typeof r);
//                        console.log(r);
                        temp = temp.replace(r, "<b style='color:Red;background-color: yellow;'>$1</b>");
                    }
                    return temp;
                }

                function loadPage(res, pi, ps) {
                    $("#page").jqPaginator({
                        totalPages: res.data.totalPage == 0 ? 1 : res.data.totalPage,
                        visiblePages: 10,
                        currentPage: pi,
                        pageSize: ps,
                        onPageChange: function (n, type) {
                            if (type == 'change') {
                                getList(n, ps);
                            }
                        }
                    });
                }

                function refeshCode() {
                    var a = $("#validate_code");
                    var src = '<c:url value="/simpleImg?rand="/>' + Math.random();
                    a.html("<a href='javascript:refeshCode()'><img src='" + src + "' width='128' height='34'></a>");
                }
            })
</script>
</body>
</html>

